<?php
include_once "checkAdmin.php";
$action = $_GET['action'];
$id = $_GET['id'];

echo "<script>console.log('$action')</script>"; // 1
echo "<script>console.log('$id')</script>"; // 2

if (!(is_numeric($action) && is_numeric($id))) {
    echo "<script>alert('参数错误');history.back();</script>";
    exit;
}

switch ($action) {
    case 0:
    case 1:
        $sql = "update user set admin = $action where id = $id ";
        break;
    default:
        echo "<script>alert('参数错误');history.back();</script>";
        exit;
}
include_once "conn.php";
//echo "<script>alert('$sql')</script>";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result)) {
    echo "<script>alert('管理员状态修改失败');history.back();</script>";
    exit;
}

echo "<script>location.replace(document.referrer);</script>";

